package com.dc.designPattern._20_state.impl;

import lombok.Data;

/**
 * Description: 状态模式_上下文环境_抽奖活动
 * @author: gdc
 * @date: 2021/6/8
 * @version 1.0
 */
@Data
public class RaffleActivity {
    /**
     * 当前的活动状态
     */
    private State state;

    /**
     * 奖品数量
     */
    private Integer count;

    private State noRaffleState = new NoRaffleState(this);
    private State canRaffleState = new CanRaffleState(this);
    private State dispenseState = new DispenseState(this);
    private State dispenseOutState = new DispenseOutState(this);

    /**
     * 初始化
     *  1、初始化当前的状态为 noRaffleState(不能抽奖状态)
     *  2、初始化奖品的数量
     * @param count         奖品的数量
     */
    public RaffleActivity(Integer count) {
        this.count = count;
        this.state = getNoRaffleState();
    }

    /**
     * 扣除积分，调用当前状态的 debuctMonty
     */
    public void debuctMoney(){
        state.deductMoney();
    }

    /**
     * 抽奖
     */
    public void raffle(){
        // 如果当前的状态是抽奖成功
        if (state.raffle()) {
            // 领取奖品
            state.dispensePrize();
        }
    }

    /**
     * 这里重写了方法，没领取一次奖品，count--
     * @return              奖品的数量
     */
    public int getCount() {
        int curCount = this.count;
        System.out.println("当前剩余奖品数：" + curCount);
        if (curCount <= 0) {
            return curCount;
        }

        this.count--;
        return curCount;
    }

}
